#include ladyluckbiggraphics.txt

var testbackgrounds = [];
var testbackgroundnum = 0;
if(variables.test) {
	testbackgrounds = ["equipment_mountain", "equipment_darkforest"];
}

changebackground(variables.background);

fadein();

actor("Lady Luck", screenwidthmid - 100, screenheightmid + 200, Col.YELLOW, LEFT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
wait(0.2);

var ladyluck = ladyluck_big;

ladyluck.x = -ladyluck.getwidth("idle");
var currenttalkingstate = "talking";
var currentidlestate = "idle";

if(variables.messages.length > 0){
  var message = variables.messages[0];
	if (message.state == "normal" || message.state == "") {
		currenttalkingstate = "talking";
		currentidlestate = "idle";
	} else {
		currenttalkingstate = "talking-"+message.state;
		currentidlestate = "idle-"+message.state;
	}
	if(!ladyluck.hasstate(currenttalkingstate)) {
		currenttalkingstate = "talking";
		currentidlestate = "idle";
	}
}

ladyluck.show(currentidlestate);
Actuate.tween(ladyluck, 1, { x: 0 }).ease(Sine.easeOut);
wait(1);

if(variables.test) {
	ladyluck.show("talking", true);
	speak("Lady Luck", "Ahem. Testing! 1, 2, 3! Here we go!");
	ladyluck.show("idle", true);
	wait(1);
}

for(message in variables.messages) {
  var mood = "normal";
  var speakstate = speakstatecheck(message.text);
  if(speakstate != ""){
    currenttalkingstate = "talking-"+speakstate;
		currentidlestate = "idle-"+speakstate;
		mood = speakstate;
  }else if (message.state == "normal" || message.state == "") {
		currenttalkingstate = "talking";
		currentidlestate = "idle";
		mood = "normal";
	} else {
		currenttalkingstate = "talking-"+message.state;
		currentidlestate = "idle-"+message.state;
		mood = message.state;
	}
	
	if(!ladyluck.hasstate(currenttalkingstate)) {
		currenttalkingstate = "talking";
		currentidlestate = "idle";
		mood = "normal";
	}
	
	ladyluck.show(currenttalkingstate, true);
	updateladylucktextboxposition(currenttalkingstate);
	
	if(variables.test && message.text == "-") {
    if (message.state == "normal" || message.state == "") {
      ladyluck.show("idle", true);
    }else{
      ladyluck.show("idle-" + message.state, true);
    } 
		cleanuptextboxes();
		var bg = testbackgrounds[testbackgroundnum % testbackgrounds.length];
		testbackgroundnum++;
		//trace(bg);
		changebackground(bg);
		sfx("cardappear");
		wait(1);
	} else {
		speak("Lady Luck", message.text, mood);
	}
	
}
ladyluck.show(currentidlestate, true);
wait(0.35);
Actuate.tween(ladyluck, 1, { x: screenwidth + 600 }).ease(Sine.easeOut);
wait(0.35);

if(variables.test) {
	returntotitle();
} else {
	startgame();
}